<?php

namespace app\api\controller;

use app\common\controller\ApiBase;
use app\Constant\ApiConstant;
use app\model\DistributionSetting;
use think\response\Json;

class Level extends ApiBase
{
	/**
	 * 分佣比例列表
	 *
	 * @return Json
	 */
	public function commissionRatioList(): Json
	{
		$info  = DistributionSetting::field('id, type, value')->where('uuid', 'setting')->find();
		$value = json_decode($info['value'], true);

		$resultList = [];
		foreach ($value as $index => $item) {
			$resultList[] = [
				'index' => $index + 1,
				'level' => $item['name'],
				'ratio' => $item['ratio'] / 100,
			];
		}

		return $this->callback(ApiConstant::SUCCESS, 'success', $resultList);
	}
}